<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input v-model="userInfo.mobile" style="width: 220px" />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <upload-img v-model="userInfo.staffPhoto" />
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="hAdd">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserDetailAPI, updateUserLoginAPI } from '@/api/employee'
export default {
  data() {
    return {
      userInfo: {
        mobile: '',
        timeOfEntry: '',
        staffPhoto: ''
      }
    }
  },
  created() {
    this.iniUserDetailInfo()
  },
  methods: {
    // 获取信息
    async iniUserDetailInfo() {
      try {
        const res = await getUserDetailAPI(this.$route.query.id)
        // console.log('', res)
        // 保存数据
        this.userInfo = res.data
      } catch (err) {
        console.log('', err)
      }
    },
    // 更新信息
    async doAdd() {
      try {
        await updateUserLoginAPI(this.userInfo)
        this.$message.success('更新成功')
        // 保存数据
      } catch (err) {
        console.log('', err)
      }
    },
    // 点击更新按钮
    hAdd() {
      this.doAdd()
    }
  }
}
</script>

<style scoped lang="scss">
.user-info {
  padding-top: 20px;
}
</style>
